package com.test.controller;

import com.test.domain.Employee;
import com.test.domain.Result;
import com.test.domain.Utils;
import com.test.service.CustomerService;
import com.test.service.EmployeeService;
import org.springframework.web.bind.annotation.*;

import java.security.NoSuchAlgorithmException;

@CrossOrigin
@RestController
@RequestMapping("/employee")
public class EmployeeController {


    private final EmployeeService employeeService;

    private final CustomerService customerService;

    public EmployeeController(EmployeeService employeeService, CustomerService customerService) {
        this.employeeService = employeeService;
        this.customerService = customerService;
    }

    @PostMapping("/login")
    public Result Login(@RequestParam("key") String key,
                        @RequestBody Employee employee) throws NoSuchAlgorithmException {
        return Utils.success(employeeService.Login(employee,key));
    }

    @GetMapping("/member")
    public Result Member(){
        customerService.updateMember();

        return Utils.success("ok");
    }

    @GetMapping("/getAllList")
    public Result getAllList(){
        return Utils.success(customerService.getAllCustomerList());
    }

    @GetMapping("/forbidden")
    public Result forbidden(@RequestParam("customerPhoneNumber") String customerPhoneNumber,
                            @RequestParam("employeeNumber")String employeeNumber){

        customerService.forbidden(employeeNumber,customerPhoneNumber);
        return Utils.success("ok");
    }
}
